<template>
<view class="page-all">
	<Header title="选择指标" bgColor="#fff" :leftIconSize="20" ></Header>
	<view class="search-content">
		<view class="left">
			<uv-search placeholder="检查指标" bgColor="#fff" v-model="keyword" :showAction="false" @change="searchFun()" @clear="clearFun()"  @blur="searchFun()"></uv-search>
		</view>
	</view>
	<!--学校列表-->
  <view v-if="emptyFlag" class="empty-box">
    <uv-empty mode="data" icon="/static/image/no-data.png" width="200rpx" height="260rpx" text="&nbsp;"/>
  </view>

	<view class="school-list" v-else>
		<uv-radio-group v-model="radiovalue">
			<view class="container" v-if="dataList.length > 0">
				<view class="item" style="height: auto"  v-for="(item,index) in dataList" :key="index">
					<view class="radio">
						<uv-radio :name="item.id">
							<template #default><view class="name">{{item.name}}</view></template>
						</uv-radio>
					</view>
				</view>
			</view>
    </uv-radio-group>
  </view>
	<!--筛选弹层-->
	<view class="check-bottom-box" @click.stop>
	  <button class="sure-button" @click.stop="submit()">确认</button>
	</view>

</view>
</template>

<script setup>
import {getCurrentInstance, ref} from 'vue'
import {onLoad, onShow} from '@dcloudio/uni-app';
import targetAPI from "@/api/law/target/target";
const {proxy} = getCurrentInstance();
const userInfo = ref(uni.getStorageSync('userInfo'));
const radiovalue = ref('')
const temp = ref('')
const keyword = ref('')
const entryType = ref(uni.getStorageSync('entryType'));
let dataList=ref([])
const emptyFlag = ref(false);
//获取指标列表
let getTargetList = async () => {
  let res = await proxy.http.asyncPost(targetAPI.targetList, {entryType:entryType.value,createOrgId:userInfo.value.user.orgId,name:keyword.value});
  if (res.code === 0) {
    dataList.value =  [...res.data];
    // radioHandle()
    emptyFlag.value = dataList.value.length <= 0;
  }
}
onLoad((option) => {
  if (option.radiovalue) {
    radiovalue.value=option.radiovalue;
  }
});

// function radioHandle(){
//     let object = dataList.value.find(item => item.id === temp.value)
//     radiovalue.value = object ? object.id : ''
// }

// function radiovalueChange(e){
//     temp.value = e
// }

//返回把选中指标数据传回
function submit(){
  uni.navigateBack({
    delta: 1,
    success: function(res) {
    let currentObj = dataList.value.filter((item=>item.id == radiovalue.value))
      uni.$emit('indexData', currentObj)
    }
  })
}
let searchFun = () => {
  getTargetList();
};
/** 清空搜索 */
let clearFun = () => {
  getTargetList();
}
//页面加载
onShow(async () => {
  await getTargetList();
})
</script>

<style scoped>
	.search-content .left{
		margin-right: 0;
	}
  .name {
	  flex: 1;
	  padding: 30rpx 0;
	  margin-left: 16rpx;
	  padding-left: 0!important;
	  position: relative;
  }
  .empty-box {
    background-color: #fff!important;
  }
  .school-list{
    height: calc(100vh - 44px - 91px - 136rpx)!important;
    overflow-y: auto!important;
  }
</style>
